pipeline{
        agent {
            label 'parallel-execute'
        }
    parameters {
        string(defaultValue:'流水线 ', description:'case_name', name: 'case_name' )
        string(defaultValue:'http://192.168.1.132:31966/', description:'serve', name: 'serve' )
        string(defaultValue:'http://192.168.1.132:30098/', description:'apiserve', name: 'apiserve' )
        string(defaultValue: '-sv', description:'args', name:'args')
        choice(choices: [
            'Tests/test_v2/test_datasource/test_527.py',
            'Tests/test_v2/test_task/test_data_copy_base/test_01initial.py',
            'Tests/test_v2/test_task/test_data_copy_base/test_02cdc.py',
            'Tests/test_v2/test_task/test_data_copy_base/test_03initial_cdc.py',
            'Tests/test_v2/test_task/test_data_development_base/test_01initial.py',
            'Tests/test_v2/test_task/test_data_development_base/test_02cdc.py',
            'Tests/test_v2/test_task/test_data_development_base/test_03initial_cdc.py'
            ], description:'案例路径', name: 'case_path')

    }
    environment{
     case_name="${params.case_name}"
     serve="${params.serve}"
     apiserve="${params.apiserve}"
     args="${params.args}"
     case_path="${params.case_path}"
    }
    stages{
                stage('自动化代码拉取'){
            steps{
                git credentialsId: '6d4b2ef1-d943-44af-9965-87f8c6a09fcd', url: 'https://e.coding.net/tapdata/tapdata/tap-client-v3.git/'
            }

        }
        stage('环境初始化'){
            steps{
                script{
                    sh '''
                        echo $server
                        # oracle instance client
                        export ORACLE_HOME=/usr/lib/oracle/11.2/client64
                        export TNS_ADMIN=$ORACLE_HOME/network/admin
                        export NLS_LANG='simplified chinese_china'.ZHS16GBK
                        export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
                        export PATH=$ORACLE_HOME/bin:$PATH
                        # requirement install
                        /usr/bin/pip376 install -r requirements.txt
                        #
                        # 更新执行环境
                        /usr/bin/python376 -m pytest -sv --jenkinsEnv=pipeline  Tests/test_v2/test_jenkins_init.py
                        /usr/bin/python376 -m pytest -sv --serve=$serve --apiserve=$apiserve Tests/test_v2/test_v2init.py
                        # 获取tapdata version
                        /usr/bin/python376 -m pytest -sv Tests/test_v2/test_get_version.py
                    '''
                }
            }

        }
        stage('案例执行'){
            steps{
                script{
                    sh '/usr/bin/python376 -m pytest $args $case_path --report-log=pytest_result.json --alluredir ./allure-results --clean-alluredir'
                }
            }

        }
}
    post{
        always {
        allure includeProperties: false, jdk: '', results: [[path: 'allure-results']]
        script{
            sh '''
                # feishu webhook report
                /usr/bin/python376 -m pytest  -sv Tests/test_util/test_feishu_report.py
                # set allure env
                mv ./environment.properties ./allure-results
            '''
        }
        }

    }

}